//
//  GCMMyNoticeViewController.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/3/11.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMMyNoticeViewController.h"
#import "GCMMyNoticeHttpRequst.h"
#import "GCMNoticeTableViewCell.h"
#import "GCMNoticeListModel.h"
#import "GCMNoticeDetailViewController.h"
@interface GCMMyNoticeViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation GCMMyNoticeViewController{
    
    NSMutableArray *_dataSource;
    UITableView *_tableV;
}
-(void)viewWillAppear:(BOOL)animated{

    self.navigationController.navigationBarHidden = NO;
    [self downLoadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self createTableView];
    [self downLoadData];
    
    
    
}

-(void)createTableView{

    _tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT )];
    _tableV.delegate = self;
    _tableV.dataSource =self;
    _tableV.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
    [self.view addSubview:_tableV];
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GCMNoticeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[GCMNoticeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    [cell setBackgroundColor:[UIColor colorWithRed:.93 green:.93 blue:.93 alpha:1]];
    
    GCMNoticeListModel *listModel = _dataSource[indexPath.row];
    NSLog(@"%@",listModel.title);
    [cell setNoticeModel:listModel];
    
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 120;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GCMNoticeDetailViewController * detailVC = [[GCMNoticeDetailViewController alloc]init];
    GCMNoticeListModel *model = _dataSource[indexPath.row];
    detailVC.idd = model.idd;
    [self.navigationController pushViewController:detailVC animated:YES ];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"通知详情";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = backItem;
}


-(void)downLoadData{

    [GCMMyNoticeHttpRequst postDataWithUserName:[GCMUserInfo instance].realName WithDepart:[GCMUserInfo instance].departId WithPage:@"1" Success:^(id obj, id noticeModel, NSError *err) {
        _dataSource  = noticeModel;
        NSLog(@"hh%@",noticeModel);
        [_tableV reloadData];
    }];
}

-(void)initData{
    
    _dataSource = [[NSMutableArray alloc]init];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
